

export const toast = (title,icon="none",duration=2000) =>{
  wx.showToast({
    title,
    icon,
    duration,
    mask:true
  })
}

//简单的进行封装请求的接口
export const request = (name,data,isLoading=false) => {
  !isLoading && wx.showLoading({
    title: '加载中'
  })
  return new Promise((resolve,rejects)=>{
    wx.cloud.callFunction({
      name,
      data,
      success:res=>{
        console.log('请求成功,',name,'===========',data,'============',res);
        !isLoading && wx.hideLoading()
        resolve(res)
      },fail:msg=>{
        console.log('请求失败',name,'===========',data,'============',msg);
        !isLoading && wx.hideLoading()
        toast(msg.message);
        rejects(msg)
      }
    })
  })
}